package com.nbsaas.boot;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.JSONArray;

import java.util.Arrays;

public class Test {
    public static void main(String[] args) {
        String jsonStr = "{\"groups\":[\"231\",\"123\"]}";

        JSONObject obj = JSON.parseObject(jsonStr);
        JSONArray array = obj.getJSONArray("groups");

        // 转成 Java String[]
        if (array != null){
            String[] groups = array.toArray(new String[0]);

            for (String g : groups) {
                System.out.println(g);
            }
        }

        String[] groups1 = obj.getObject("groups", String[].class);
        if (groups1 != null) {
            System.out.println("groups1:"+Arrays.asList(groups1));
        }
    }
}
